#pragma once
#include <QWidget>
#include <QFrame>
#include <QPushButton>
#include <QGraphicsDropShadowEffect>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QMouseEvent>
#include <QProcess>
#include <QEventLoop>
#include <shlobj.h>
#include <messageinfomation.h>

#define TEST_ARGMENTS                       0

#define CONFIG_GENERAL      "general_config"
#define CONFIG_PRODUCT_REGION   "product_region"
#define REG_PATH						"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"

QT_BEGIN_NAMESPACE
namespace Ui { class BkWidget; }
QT_END_NAMESPACE

extern QString g_deleteApplicationDir;


class Worker : public QObject {
    Q_OBJECT
public slots:
    void doWork();

signals:
    void currentProcess(int value);
    void workResult(bool value);
};

class BkWidget : public QWidget
{
    Q_OBJECT
public:
    explicit BkWidget(QWidget *parent = nullptr);
    ~BkWidget();

    void initConnection();
    void initSettings();
    void initData();
    void initView();


protected:
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    bool eventFilter(QObject *obj, QEvent *event) override;

private:
    bool isProcessRunning();
    IShellFolder* getIShellFolderByPath(QString path);
    void getDeskAndAppPath(wchar_t* DeskTop, wchar_t* AppData);
    bool getIEunmIDList(IShellFolder* m_pShellFolder, wchar_t* path);
    bool delDesktopIShellFolder();
    void deleteRegPath();
    bool selfDelete();
    void readReg();
    void deleteApplicationFile();
    void onCheckProgram(const int msgType, int closeType);

    bool m_dragging = false;
    QPoint m_dragPosition;
    Ui::BkWidget *ui;
    QString m_productName = "";
    int m_productRegion = 1;
    QString m_isntallAppId = "";
    quint64 m_totalSize = 0;
    quint64 m_currentSize = 0;
    MessageInfomation* m_messageBox = nullptr;
    MessageInfomation::emCloseType m_mssageCloseType = MessageInfomation::kClose;
    QThread* m_thread = nullptr;
    Worker m_worker;
};
